package com.company.management.controller.report;

import cn.hutool.core.util.StrUtil;

import com.company.management.controller.report.rep.APIResult;
import com.company.management.controller.report.vo.ReportCommentReqVO;
import com.company.management.controller.report.vo.ReportContextReqVO;
import com.company.management.controller.report.vo.UserReportCommentRespVO;
import com.company.management.controller.report.vo.UserReportRespVO;
import com.company.management.exception.MessageException;
import com.company.management.service.report.ReportServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Anis
 */
@Api(tags = "汇报模块", value = "ReportController")
@RestController
@RequestMapping("/api/report")
@Slf4j
public class ReportController {

    @Resource
    private ReportServices reportServices;

    @PostMapping("/create")
    @ApiOperation("创建汇报")
    public APIResult createReport(@RequestBody ReportContextReqVO reqVO) {
        Long reportId = reportServices.createReport(reqVO);

        return APIResult.ok(reportId);
    }

    /**
     * 获取登录用户汇报数据.这里先模拟使用 --1
     *
     * @return
     */
    @GetMapping("/get")
    @ApiOperation("获取用户汇报数据")
    public APIResult getReportList(ReportContextReqVO reqVO) {
        List<UserReportRespVO> list = reportServices.getReportByUserId(reqVO);

        return APIResult.ok(list);
    }

    @PostMapping("/comment/create")
    @ApiOperation("创建评论")
    public APIResult createReportComment(@RequestBody ReportCommentReqVO reqVO) {
        if (reqVO.getReportId() == null || reqVO.getCommentContent() == null || reqVO.getUserId() == null) {
            throw new MessageException("参数异常");
        }
        List<UserReportCommentRespVO> reportComment = reportServices.createReportComment(reqVO);
        return APIResult.ok(reportComment);
    }

    @GetMapping("/comment/get")
    @ApiOperation("获取评论")
    public APIResult getReportComment(@RequestParam Long reportId) {
        List<UserReportCommentRespVO> reportComment = reportServices.getReportComment(reportId);
        return APIResult.ok(reportComment);
    }
}
